/*
 * Copyright © 2024-2025 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#include "../include/time.h"

/**
 * @brief Convert a time structure into a string representing the local time.
 *
 * @param timeptr Pointer to a Ttm structure containing the time to convert.
 * @return A pointer to a string representing the time in the format "Day Mon DD HH:MM:SS YYYY".
 */
char *Sasctime(const struct Ttm *timeptr) {
    static char buffer[26];
    snprintf(buffer, sizeof(buffer), "%c %2d %02d:%02d:%02d %d",
             "Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat"[timeptr->tm_wday * 4],
             timeptr->tm_mday,
             timeptr->tm_hour,
             timeptr->tm_min,
             timeptr->tm_sec,
             1900 + timeptr->tm_year);
    return buffer;
}
